Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot update on getting attributes #757

Merged
merged 1 commit into from
Apr 23, 2024
Merged

Conversation

pfebrer
Copy link
Contributor

@pfebrer pfebrer commented Apr 23, 2024

With this PR plots are updated if one attempts to retreive an attribute that we know will be present in the figure.

This is to make things like plot.show() even when no plot has been computed yet. It was not intuitive for users that you had to plot.get().show(). This has the side effect that plot.show() will now update the plot.This means that the way of acting on the plot without updating it now is by getting the _output attribute. E.g. to show the current (possibly outdated) plot:

plot._output.show()

It fixes the broken docs.

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 35.00000% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 86.74%. Comparing base (0b964fe) to head (499feb6).

Files Patch % Lines
src/sisl/viz/figure/matplotlib.py 28.57% 5 Missing ⚠️
src/sisl/viz/plot.py 16.66% 5 Missing ⚠️
src/sisl/viz/figure/plotly.py 50.00% 2 Missing ⚠️
src/sisl/viz/figure/figure.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #757      +/-   ##
==========================================
- Coverage   86.78%   86.74%   -0.04%     
==========================================
  Files         410      410              
  Lines       51811    51720      -91     
==========================================
- Hits        44965    44866      -99     
- Misses       6846     6854       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zerothi zerothi merged commit 8975066 into zerothi:main Apr 23, 2024
7 of 9 checks passed
@zerothi
Copy link
Owner

zerothi commented Apr 23, 2024

@pfebrer could you have a look in the latest build (I just tried to rebuild), I got this: https://github.com/zerothi/sisl/actions/runs/8799290553/job/24148053929

Can you see the output?

CellExecutionError in tutorials/tutorial_es_1.ipynb:
------------------
coord = graphene.sub(0)
coord.plot(axes="xy", atoms_style={"color": "red"}).merge(
    graphene.remove(0).plot(axes="xy")
)
------------------
----- stdout -----
plot_actions False
------------------
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 2
      1 coord = graphene.sub(0)
----> 2 coord.plot(axes="xy", atoms_style={"color": "red"}).merge(
      3     graphene.remove(0).plot(axes="xy")
      4 )
File /opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/sisl/viz/plot.py:40, in Plot.merge(self, *others, **kwargs)
     37 def merge(self, *others, **kwargs):
     38     from .plots.merged import merge_plots
---> 40     return merge_plots(self, *others, **kwargs)
File /opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/sisl/viz/plots/merged.py:44, in merge_plots(composite_method, backend, *figures, **kwargs)
     40         plot.get()
     41     return plot
     43 plot_actions = combined(
---> 44     *[_san_plot(fig).plot_actions for fig in figures],
     45     composite_method=composite_method,
     46     **kwargs,
     47 )
     49 return get_figure(plot_actions=plot_actions, backend=backend)
File /opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/sisl/viz/plot.py:31, in Plot.__getattr__(self, key)
     29         return getattr(self.nodes.output.get(), key)
     30     else:
---> 31         raise AttributeError(
     32             f"'{key}' not found in {self.__class__.__name__} with backend '{selected_backend}'"
     33         )
     34 else:
     35     return super().__getattr__(key)
AttributeError: 'plot_actions' not found in GeometryPlot with backend 'plotly'
You can ignore this error by setting the following in conf.py:
    nbsphinx_allow_errors = True
make: *** [Makefile:22: html] Error 2
Error: Process completed with exit code 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants